# Contributor: kpcyrd <git@rxv.cc>
# Maintainer: kpcyrd <git@rxv.cc>
pkgname=acme-redirect
pkgver=0.4.0
pkgrel=0
pkgdesc="Tiny http daemon that answers acme challenges and redirects everything else to https"
url="https://github.com/kpcyrd/acme-redirect"
arch="x86_64 armhf armv7" # limited by cargo
license="GPL-3.0-or-later"
makedepends="
	cargo
	openssl-dev
	scdoc
	"
subpackages="$pkgname-doc
	$pkgname-openrc
	$pkgname-bash-completion
	$pkgname-zsh-completion
	$pkgname-fish-completion
	"
install="$pkgname.pre-install"
options="net"
source="$pkgname-$pkgver.tar.gz::https://github.com/kpcyrd/acme-redirect/archive/v$pkgver.tar.gz"

build() {
	cargo build --release --locked

	mkdir -p completions
	"target/release/acme-redirect" completions bash > completions/acme-redirect.bash
	"target/release/acme-redirect" completions zsh > completions/_acme-redirect
	"target/release/acme-redirect" completions fish > completions/acme-redirect.fish

	make docs
}

check() {
	cargo test --release --locked
}

package() {
	install -Dm755 "$builddir/target/release/acme-redirect" -t "$pkgdir/usr/bin"

	install -Dm755 "$builddir/contrib/openrc/$pkgname.initd" "$pkgdir/etc/init.d/$pkgname"
	install -Dm755 "$builddir/contrib/cron/acme-redirect.cron" \
		"$pkgdir"/etc/periodic/daily/acme-redirect

	install -Dm644 "$builddir/contrib/confs/acme-redirect.conf" -t "$pkgdir/etc"
	install -Dm644 "$builddir/contrib/confs/certs.d/example.com.conf" "$pkgdir/etc/acme-redirect.d/example.com.conf.sample"

	install -Dm644 -t "$pkgdir/usr/share/man/man1" \
		"$builddir/contrib/docs/acme-redirect.1"
	install -Dm644 -t "$pkgdir/usr/share/man/man5" \
		"$builddir/contrib/docs/acme-redirect.conf.5" \
		"$builddir/contrib/docs/acme-redirect.d.5"

	install -Dm644 "$builddir/completions/acme-redirect.bash" \
		"$pkgdir/usr/share/bash-completion/completions/acme-redirect"
	install -Dm644 "$builddir/completions/_acme-redirect" \
	    "$pkgdir/usr/share/zsh/site-functions/_acme-redirect"
	install -Dm644 "$builddir/completions/acme-redirect.fish" \
		"$pkgdir/usr/share/fish/completions/acme-redirect.fish"
}

sha512sums="726cb8a28e93743ff6bb28b3f134b11980ba7731ed18900602401e595c21ff7c51f935e0cca1a98f4e69cc08bdd8ca3f5437c4450c296313d631fa9df81f8fa1  acme-redirect-0.4.0.tar.gz"
